package NextClass;

import NextClass.Native.HttpService;
import NextClass.Native.NextFile;
import vm.runtime.NextVMRuntime;

import java.util.HashMap;
import java.util.NavigableMap;

public class NextClassAPI {
    public static HashMap<String,NativeClass> nativeClassHashMap = new HashMap<>();

    public static String[] className = {
            "file",
            "http_service"
    };

    public static void loadNativeClass() {

        NativeClass file = new NativeClass();
        file.ClassName = className[0];
        file.Methods = NextFile.fileClassMethods;

        NativeClass http_service = new NativeClass();
        http_service.ClassName = className[1];
        http_service.Methods = HttpService.ClassMethods;

        nativeClassHashMap.put("file" , file);
        nativeClassHashMap.put("http_service",http_service);
    }

    public static NativeClass IsNativeClassInvokeCode(String code,NextVMRuntime nextVMRuntime) {
        try {
            String Name = code.substring(0 , code.indexOf("(")).trim();
            String ClassName = Name.substring(0,Name.indexOf(".")).trim();
            String Invoke = Name.substring(Name.indexOf(".")+1).trim();
            return (NativeClass) nextVMRuntime.values.get(ClassName);
        }
        catch (Exception e) {
            return null;
        }
    }
}
